﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
using System.Xml.Linq;
using System.IO;

namespace XiamenQudianCoffee.model
{
    public class SocketClients
    {
        private static SocketClients instance;
        private SocketClients() { }
        public static SocketClients Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new SocketClients();
                }
                return instance;
            }
        }
        /// <summary>
        /// 创建客户端
        /// </summary>
        public Socket client;
        public void socketclient()
        {
            try
            {
                ///创建客户端
                client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
                ///IP地址
                IPAddress ip = IPAddress.Parse(IPorPortInfo.Instance.CoffeeIP);
                ///端口号
                IPEndPoint endPoint = new IPEndPoint(ip, 8885);
                ///建立与服务器的远程连接
                client.Connect(endPoint);
                ClientList clientList = new ClientList();
                clientList.MsgBol = WuLiaoCoffeeSel.Instance;
                clientList.code = 4;
                var dd = JsonConvert.SerializeObject(clientList);
                client.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                Thread.Sleep(1000);
                ClientList clientList1 = new ClientList();
                clientList1.MsgBol = WuLiaoCoffeeSel.Instance;
                clientList1.code = 2;
                client.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList1)));
                Thread.Sleep(1000);
                //ClientList clientList2 = new ClientList();
                //clientList2.MsgBol = WuLiaoCoffeeSel.Instance;
                //clientList2.code = 12;
                //client.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList2)));
               // Thread.Sleep(1000);
                ///线程问题
                Thread thread = new Thread(ReciveMsg);
                thread.IsBackground = true;
                thread.Start(client);
                Thread thr = new Thread(IOMsg.Instance.IOSerial_Thr);
                thr.IsBackground = true;
                thr.Start();
                Thread thr9 = new Thread(IOMsgRobot.Instance.IOSerial_Thr);
                thr9.IsBackground = true;
                thr9.Start();
                //Thread thr10 = new Thread(CoffeeMakes.Instance.QDMsg);
                //thr10.IsBackground = true;
                //thr10.Start();
                Thread thr6 = new Thread(IceMakingMsg1.Instance.IOSerial_Thr);
                thr6.IsBackground = true;
                thr6.Start();
                Thread thr7 = new Thread(coffeeMsg.Instance.IOSerial_Thr);
                thr7.IsBackground = true;
                thr7.Start();
                Thread thr8 = new Thread(EWMMsg.Instance.IOSerial_Thr);
                thr8.IsBackground = true;
                thr8.Start();
                Thread thr11 = new Thread(CoffeeMakes.Instance.QBTimeMsg);
                thr11.IsBackground = true;
                thr11.Start();
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 客户端接收到服务器发送的消息
        /// </summary>
        /// <param name="o">客户端</param>
        void ReciveMsg(object o)
        {
            Socket client = o as Socket;
            while (true)
            {
                try
                {
                    ///定义客户端接收到的信息大小
                    byte[] arrList = new byte[1024 * 1024];
                    ///接收到的信息大小(所占字节数)
                    int length = client.Receive(arrList);
                    string msg = Encoding.UTF8.GetString(arrList, 0, length);
                    var ClientList = JsonConvert.DeserializeObject<ClientList>(msg);
                    if (ClientList != null)
                    {
                        if (ClientList.code == 0)
                        {
                            show(ClientList.message.type, ClientList.message.Name);
                        }
                        else if (ClientList.code == 3)
                        {
                            RobotShow(ClientList.message.Name, ClientList.message.type);
                            ClientList clientList = new ClientList();
                            clientList.MsgBol = WuLiaoCoffeeSel.Instance;
                            clientList.robotMsg = RobotMsg.Instance;
                            clientList.code = 3;
                            clientList.IsMake = MainWindow.isMake;
                            var list = JsonConvert.SerializeObject(clientList);
                            var msgs = Encoding.UTF8.GetBytes(list);
                            client.Send(msgs);
                        }
                        else if (ClientList.code == 6)
                        {
                            MainWindow.MakingTypes = ClientList.message.type;
                            MainWindow.img_path = ClientList.message.Name;
                        }
                    }
                }
                catch (Exception)
                {
                    ///关闭客户端
                    client.Close();
                }

            }
        }
        public void show(Double code, string msg)
        {
            try
            {
                #region 新的

                switch (msg)
                {
                    case "JG1":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG1_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG1_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ1_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG1_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG1_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "YG1":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG1_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG1_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ1_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG1_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG1_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "LGDJXJ1":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG1_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG1_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ1_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ1_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ1_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "YGDJQJ1":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJHT1_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJQJ1_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJQJ1_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJQJ1_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "YGDJHT1":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJHT1_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJQJ1_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJHT1_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJHT1_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "JG2":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG2_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG2_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ2_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG2_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG2_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "YG2":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG2_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG2_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ2_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG2_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG2_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "LGDJXJ2":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG2_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG2_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ2_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ2_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ2_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "YGDJQJ2":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJHT2_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJQJ2_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJQJ2_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJQJ2_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "YGDJHT2":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJHT2_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJQJ2_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJHT2_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJHT2_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "FYJ1":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.FYJ1_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.FYJ2_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.FYJ1_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.FYJ1_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "FYJ2":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.FYJ1_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.FYJ2_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.FYJ2_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.FYJ2_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "JG3":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG3_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG3_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ3_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG3_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG3_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "YG3":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG3_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG3_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ3_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG3_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG3_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "LGDJXJ3":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QYG3_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QJG3_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ3_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ3_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LGDJXJ3_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "YGDJQJ3":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJHT3_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJQJ3_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJQJ3_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJQJ3_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "YGDJHT3":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJHT3_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJQJ3_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJHT3_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.YGDJHT3_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "TGS1":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS1_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGX1_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS1_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS1_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "TGX1":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS1_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGX1_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGX1_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGX1_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "TGS2":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS2_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGX2_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS2_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS2_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "TGX2":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGS2_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGX2_end);
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGX2_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.TGX2_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "LB1":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LB1_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LB1_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "LG1":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LG1_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                            while (WuLiaoCoffeeSel.Instance.LidOff1_Sel_Bol) { Thread.Sleep(10); }
                            while (!WuLiaoCoffeeSel.Instance.LidOff1_Sel_Bol) { Thread.Sleep(10); }
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LG1_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LG1_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "LG2":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LG2_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LG2_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "LG3":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LG3_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.LG3_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "GT1":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT1_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT1_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "GT2":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT2_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT2_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "GT3":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT3_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT3_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "GT4":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT4_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT4_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "GT5":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT5_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT5_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "GT6":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT6_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT6_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "SF1":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.SF1_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.SF1_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "SF2":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.SF2_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.SF2_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "SF3":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.SF3_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.SF3_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "SF4":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.SF4_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.SF4_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "SF5":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.SF5_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.SF5_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "QBQJ":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QBQJ_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QBQJ_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "QBHT":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        if (code == 0)
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QBHT_start);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        else
                        {
                            IOMsg.Instance.AllBol = false;
                            Thread.Sleep(200);
                            IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.QBHT_end);
                            Thread.Sleep(200);
                            IOMsg.Instance.AllBol = true;
                        }
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "GTS1":
                        WuLiaoCoffeeSel.Instance.SugarInit1 = code == 0 ? 1 : code;
                        IPorPortInfo.Instance.SugarInit1 = code == 0 ? 1 : code;
                        IPorPortInfo porPortInfo1 = IPorPortInfo.Instance;
                        File.WriteAllText(MainWindow.IPorPortUrl, JsonConvert.SerializeObject(porPortInfo1));
                        break;
                    case "GTS2":
                        WuLiaoCoffeeSel.Instance.SugarInit1 = code == 0 ? 1 : code;
                        IPorPortInfo.Instance.SugarInit1 = code == 0 ? 1 : code;
                        IPorPortInfo porPortInfo2 = IPorPortInfo.Instance;
                        File.WriteAllText(MainWindow.IPorPortUrl, JsonConvert.SerializeObject(porPortInfo2));
                        break;
                    case "GTS3":
                        WuLiaoCoffeeSel.Instance.SugarInit1 = code == 0 ? 1 : code;
                        IPorPortInfo.Instance.SugarInit1 = code == 0 ? 1 : code;
                        IPorPortInfo porPortInfo3 = IPorPortInfo.Instance;
                        File.WriteAllText(MainWindow.IPorPortUrl, JsonConvert.SerializeObject(porPortInfo3));
                        break;
                    case "GTS4":
                        WuLiaoCoffeeSel.Instance.SugarInit1 = code == 0 ? 1 : code;
                        IPorPortInfo.Instance.SugarInit1 = code == 0 ? 1 : code;
                        IPorPortInfo porPortInfo4 = IPorPortInfo.Instance;
                        File.WriteAllText(MainWindow.IPorPortUrl, JsonConvert.SerializeObject(porPortInfo4));
                        break;
                    case "GTS5":
                        WuLiaoCoffeeSel.Instance.SugarInit1 = code == 0 ? 1 : code;
                        IPorPortInfo.Instance.SugarInit1 = code == 0 ? 1 : code;
                        IPorPortInfo porPortInfo5 = IPorPortInfo.Instance;
                        File.WriteAllText(MainWindow.IPorPortUrl, JsonConvert.SerializeObject(porPortInfo5));
                        break;
                    case "GTS6":
                        WuLiaoCoffeeSel.Instance.SugarInit1 = code == 0 ? 1 : code;
                        IPorPortInfo.Instance.SugarInit1 = code == 0 ? 1 : code;
                        IPorPortInfo porPortInfo6 = IPorPortInfo.Instance;
                        File.WriteAllText(MainWindow.IPorPortUrl, JsonConvert.SerializeObject(porPortInfo6));
                        break;
                    case "CSGT1":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        IOMsg.Instance.AllBol = false;
                        Thread.Sleep(200);
                        IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT1_start);
                        Thread.Sleep(Convert.ToInt32(code == 0 ? 1 : code) * 1000);
                        IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT1_end);
                        Thread.Sleep(200);
                        IOMsg.Instance.AllBol = true;
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "CSGT2":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        IOMsg.Instance.AllBol = false;
                        Thread.Sleep(200);
                        IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT2_start);
                        Thread.Sleep(Convert.ToInt32(code == 0 ? 1 : code) * 1000);
                        IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT2_end);
                        Thread.Sleep(200);
                        IOMsg.Instance.AllBol = true;
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "CSGT3":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        IOMsg.Instance.AllBol = false;
                        Thread.Sleep(200);
                        IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT3_start);
                        Thread.Sleep(Convert.ToInt32(code == 0 ? 1 : code) * 1000);
                        IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT3_end);
                        Thread.Sleep(200);
                        IOMsg.Instance.AllBol = true;
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "CSGT4":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        IOMsg.Instance.AllBol = false;
                        Thread.Sleep(200);
                        IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT4_start);
                        Thread.Sleep(Convert.ToInt32(code == 0 ? 1 : code) * 1000);
                        IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT4_end);
                        Thread.Sleep(200);
                        IOMsg.Instance.AllBol = true;
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "CSGT5":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        IOMsg.Instance.AllBol = false;
                        Thread.Sleep(200);
                        IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT5_start);
                        Thread.Sleep(Convert.ToInt32(code == 0 ? 1 : code) * 1000);
                        IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT5_end);
                        Thread.Sleep(200);
                        IOMsg.Instance.AllBol = true;
                        IOMsg.Instance.CFBol = true;
                        break;
                    case "CSGT6":
                        while (!IOMsg.Instance.CFBol) { Thread.Sleep(100); }
                        IOMsg.Instance.CFBol = false;
                        IOMsg.Instance.AllBol = false;
                        Thread.Sleep(200);
                        IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT6_start);
                        Thread.Sleep(Convert.ToInt32(code == 0 ? 1 : code) * 1000);
                        IOSerialPort.Instance.SerialSend(CoffeeIOModel.Instance.GT6_end);
                        Thread.Sleep(200);
                        IOMsg.Instance.AllBol = true;
                        IOMsg.Instance.CFBol = true;
                        break;
                    default:
                        break;
                }
                #endregion
                #region 旧的
                //IOMsg.Instance.AllBol = false;
                //Thread.Sleep(100);
                //switch (msg)
                //{
                //    case "TGS_BTN":
                //        if (code == 0)
                //        {
                //            IOMsg.Instance.AllBol = false;
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.PushRod_UP_end);
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.PushRod_Down_end);
                //            Thread.Sleep(100);

                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.PushRod_UP_start);

                //            Thread.Sleep(100);
                //            IOMsg.Instance.AllBol = true;
                //        }
                //        else
                //        {
                //            IOMsg.Instance.AllBol = false;
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.PushRod_UP_end);
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.PushRod_Down_end);
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.PushRod_UP_end);
                //            Thread.Sleep(100);
                //            IOMsg.Instance.AllBol = true;
                //        }
                //        break;
                //    case "TGX_BTN":
                //        if (code == 0)
                //        {
                //            IOMsg.Instance.AllBol = false;
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.PushRod_UP_end);
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.PushRod_Down_end);
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.PushRod_Down_start);
                //            Thread.Sleep(100);
                //            IOMsg.Instance.AllBol = true;
                //        }
                //        else
                //        {
                //            IOMsg.Instance.AllBol = false;
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.PushRod_UP_end);
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.PushRod_Down_end);
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.PushRod_Down_end);
                //            Thread.Sleep(100);
                //            IOMsg.Instance.AllBol = true;
                //        }
                //        break;
                //    case "LB8":
                //        if (code == 0)
                //        {
                //            IOMsg.Instance.AllBol = false;
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.Drop_Cup_start);
                //            Thread.Sleep(100);
                //            IOMsg.Instance.AllBol = true;
                //        }
                //        else
                //        {
                //            IOMsg.Instance.AllBol = false;
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.Drop_Cup_end);
                //            Thread.Sleep(100);
                //            IOMsg.Instance.AllBol = true;
                //        }
                //        break;
                //    case "LB12":
                //        if (code == 0)
                //        {
                //            IOMsg.Instance.AllBol = false;
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.Drop_Cup2_start);
                //            Thread.Sleep(100);
                //            IOMsg.Instance.AllBol = true;
                //        }
                //        else
                //        {
                //            IOMsg.Instance.AllBol = false;
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.Drop_Cup2_end);
                //            Thread.Sleep(100);
                //            IOMsg.Instance.AllBol = true;
                //        }
                //        break;
                //    case "CCMSS":
                //        if (code == 0)
                //        {
                //            IOMsg.Instance.AllBol = false;
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.PushRod_UP_start);
                //            Thread.Sleep(100);
                //            IOMsg.Instance.AllBol = true;
                //        }
                //        else
                //        {
                //            IOMsg.Instance.AllBol = false;
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.PushRod_UP_end);
                //            Thread.Sleep(100);
                //            IOMsg.Instance.AllBol = true;
                //        }
                //        break;
                //    case "CCMXJ":
                //        if (code == 0)
                //        {
                //            IOMsg.Instance.AllBol = false;
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.PushRod_Down_start);
                //            Thread.Sleep(100);
                //            IOMsg.Instance.AllBol = true;
                //        }
                //        else
                //        {
                //            IOMsg.Instance.AllBol = false;
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.PushRod_Down_end);
                //            Thread.Sleep(100);
                //            IOMsg.Instance.AllBol = true;
                //        }
                //        break;
                //    case "GTZ1":
                //        if (code == 0)
                //        {
                //            IOMsg.Instance.AllBol = false;
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.GT1_start);
                //            Thread.Sleep(100);
                //            IOMsg.Instance.AllBol = true;
                //        }
                //        else
                //        {
                //            IOMsg.Instance.AllBol = false;
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.GT1_end);
                //            Thread.Sleep(100);
                //            IOMsg.Instance.AllBol = true;
                //        }
                //        break;
                //    case "GTZ2":
                //        if (code == 0)
                //        {
                //            IOMsg.Instance.AllBol = false;
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.GT2_start);
                //            Thread.Sleep(100);
                //            IOMsg.Instance.AllBol = true;
                //        }
                //        else
                //        {
                //            IOMsg.Instance.AllBol = false;
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.GT2_end);
                //            Thread.Sleep(100);
                //            IOMsg.Instance.AllBol = true;
                //        }
                //        break;
                //    case "GTZ3":
                //        if (code == 0)
                //        {
                //            IOMsg.Instance.AllBol = false;
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.GT3_start);
                //            Thread.Sleep(100);
                //            IOMsg.Instance.AllBol = true;
                //        }
                //        else
                //        {
                //            IOMsg.Instance.AllBol = false;
                //            Thread.Sleep(100);
                //            IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.GT3_end);
                //            Thread.Sleep(100);
                //            IOMsg.Instance.AllBol = true;
                //        }
                //        break;
                //    case "GT1":
                //        MainWindow.SugarInit1 = code == 0 ? 1 : code;
                //        WuLiaoCoffeeSel.Instance.SugarInit1 = code == 0 ? 1 : code;
                //        IPorPortInfo.Instance.SugarInit1 = code == 0 ? 1 : code;
                //        IPorPortInfo porPortInfo1 = IPorPortInfo.Instance;
                //        File.WriteAllText(MainWindow.IPorPortUrl, JsonConvert.SerializeObject(porPortInfo1));

                //        break;
                //    case "CSGT1":
                //        IOMsg.Instance.AllBol = false;
                //        Thread.Sleep(100);
                //        IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.GT1_start);
                //        Thread.Sleep(Convert.ToInt32(code == 0 ? 1 : code) * 1000);
                //        IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.GT1_end);
                //        Thread.Sleep(100);
                //        IOMsg.Instance.AllBol = true;
                //        break;
                //    case "GT2":
                //        MainWindow.SugarInit2 = code == 0 ? 1 : code;
                //        WuLiaoCoffeeSel.Instance.SugarInit2 = code == 0 ? 1 : code;
                //        IPorPortInfo.Instance.SugarInit2 = code == 0 ? 1 : code;
                //        IPorPortInfo porPortInfo2 = IPorPortInfo.Instance;
                //        File.WriteAllText(MainWindow.IPorPortUrl, JsonConvert.SerializeObject(porPortInfo2));
                //        break;
                //    case "CSGT2":
                //        IOMsg.Instance.AllBol = false;
                //        Thread.Sleep(100);
                //        IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.GT2_start);
                //        Thread.Sleep(Convert.ToInt32(code == 0 ? 1 : code) * 1000);
                //        IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.GT2_end);
                //        Thread.Sleep(100);
                //        IOMsg.Instance.AllBol = true;
                //        break;
                //    case "GT3":
                //        MainWindow.SugarInit3 = code == 0 ? 1 : code;
                //        WuLiaoCoffeeSel.Instance.SugarInit3 = code == 0 ? 1 : code;
                //        IPorPortInfo.Instance.SugarInit3 = code == 0 ? 1 : code;
                //        IPorPortInfo porPortInfo3 = IPorPortInfo.Instance;
                //        File.WriteAllText(MainWindow.IPorPortUrl, JsonConvert.SerializeObject(porPortInfo3));

                //        break;
                //    case "CSGT3":
                //        IOMsg.Instance.AllBol = false;
                //        Thread.Sleep(100);
                //        IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.GT3_start);
                //        Thread.Sleep(Convert.ToInt32(code == 0 ? 1 : code) * 1000);
                //        IOSerialPort.Instance.SerialSend(DigitalMsg.Instance.GT3_end);
                //        Thread.Sleep(100);
                //        IOMsg.Instance.AllBol = true;
                //        break;
                //    default:
                //        break;
                //}
                //Thread.Sleep(100);
                //IOMsg.Instance.AllBol = true;
                #endregion
                ClientList clientList = new ClientList();
                MessageClientList coffeelist = MessageClientList.Instance;
                coffeelist.Name = msg;
                coffeelist.type = code == 1 ? 0 : 1;
                clientList.message = coffeelist;
                clientList.code = 0;
                client.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
            }
            catch (Exception)
            {
            }
        }
        /// <summary>
        ///   状态  0 关状态  1 开状态 2 已开机 3 上电 4 下电 5 已使能 6 下使能 7 已运行 8 继续运行 9 已报警 10 已暂停  11已停止 ,12 机械臂状态查询
        /// </summary>
        /// <param name="name"></param>
        /// <param name="Type"></param>
        public void RobotShow(string name, double Type)
        {
            try
            {
                switch (Type)
                {
                    case 3:
                        jakaAPI.power_on(ref RobotOperate.handle1);
                        break;
                    case 4:
                        jakaAPI.power_off(ref RobotOperate.handle1);
                        break;
                    case 5:
                        jakaAPI.enable_robot(ref RobotOperate.handle1);
                        break;
                    case 6:
                        jakaAPI.disable_robot(ref RobotOperate.handle1);
                        break;
                    case 7:
                        jakaAPI.program_run(ref RobotOperate.handle1);
                        break;
                    case 8:
                        jakaAPI.program_resume(ref RobotOperate.handle1);
                        break;
                    case 9:
                        jakaAPI.clear_error(ref RobotOperate.handle1);
                        break;
                    case 10:
                        jakaAPI.program_pause(ref RobotOperate.handle1);
                        break;
                    case 11:
                        jakaAPI.program_abort(ref RobotOperate.handle1);
                        break;
                }
                RobotOperate.Instance.Robot_L_Show();
            }
            catch (Exception)
            {
            }
        }
    }
}
